-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Upgrade test fixtures to 2.x project layouts #1301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5ce2eb6
to
7349a80
Compare
"foreignKey": "userId", | ||
"options": { | ||
"disableInclude": true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, this option is not covered by your new tests, because the tests are explicitly overriding this option in models.json
. Please consider writing few more test to verify that a) the built-in user disables include of access tokens b) user submodels inherit this setting by default too.
The model change is not covered by tests. Other than that, the patch LGTM. |
9abcb08
to
68a2344
Compare
@bajtos PTAL again. I had to convert the test apps into LB 2.x layout, which is a great side effect. |
For posterity, can you please explain why was this needed?
|
app.use(apiPath, loopback.rest()); | ||
app.use(loopback.static(path.join(__dirname, 'public'))); | ||
app.use(loopback.urlNotFound()); | ||
app.use(loopback.errorHandler()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason why you are not using middleware.json
and middleware phases in this app?
Are your tests relying on cookieParser
at all? And why do they need static files from the public
directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I just copied them from the existing fixture. I can clean them up.
Actually I think this is a wrong thing to do. LoopBack tests should not depend on loopback-boot, they should setup the application via code only.
IIRC, the main reason why the existing LoopBack tests are depending on loopback-boot is to ensure that LoopBack 1.x apps can be upgraded to LoopBack 2.x + loopback-boot 1.x with no breaking changes. I think this issue deserves some discussion and it will be best to decouple it from your work on "Set disableInclude for User->AccessToken relation". Is there any way how to finish your fix without upgrading loopback-boot? |
The project already has dependency on Migrating from 1.x to 2.x is not a main concern any more. I think it's better to use 2.x layout as developers sometimes try to follow what we do. If you feel strongly about removing the test fixtures, we can discuss that as a separate issue. With 1.x layout, there is no way to use the base class such as |
68a2344
to
bb3f971
Compare
I dig up the commit that added the dependency on loopback-boot - see c896c78. It seems the change was made purely in order to support test fixtures booting the app via However, I still believe that we should keep the number of fixtures as small as possible, create loopback apps inside the tests purely code-wise and keep these apps as small as possibly. |
bb3f971
to
b6efccc
Compare
I decoupled the LB 2.x upgrade from |
// to the wrong app instance | ||
defaultApp = loopback.User.app; | ||
loopback.User.app = null; | ||
User = loopback.User.extend('TestUser', {}, {http: {path: 'test-users'}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason why your are not using HTTP path /users
? That way you will not have to change URLs in all the test cases below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because the model in use is a sub-model of User. If we don't explicitly specify http.path
, it will default to /testusers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So why can't you specify http.path: 'users'
, or even plural: 'Users'
, since you are already overriding the default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyways. If you believe that it's better to have /test-users
URL even at the cost of making future code archaeology more difficult, then I can live with that.
@@ -78,7 +88,7 @@ describe('User', function() { | |||
assert(err); | |||
assert.equal(err.name, 'ValidationError'); | |||
assert.equal(err.statusCode, 422); | |||
assert.equal(err.details.context, 'user'); | |||
assert.equal(err.details.context, 'TestUser'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following is better as it should be resistant against future changes:
assert.equal(err.details.context, TestUser.modelName);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Fixed.
b6efccc
to
12e19e3
Compare
LGTM. |
…ss-tokens Upgrade test fixtures to 2.x project layouts
/to @bajtos
/cc @ritch
See #386